home *** CD-ROM | disk | FTP | other *** search
/ SIGGRAPH 2002 Course Notes / SIGGRAPH 2002 - Course Notes - Disc 1.iso / pc / notes / 16 / supplemental-material / Pharr / velvet.sl < prev   
Encoding:
Text File  |  2002-04-05  |  2.2 KB  |  75 lines

  1. /* Renamed to SHW_velvet.sl -- tal@cs.caltech.edu */
  2.  
  3. /*
  4.  * velvet.sl -- velvet
  5.  *
  6.  * DESCRIPTION:
  7.  *   An attempt at a velvet surface.
  8.  *   This phenomenological model contains three compnents:
  9.  *   - A retroreflective lobe (back toward the light source)
  10.  *   - Scattering near the horizon, regardless of incident direction
  11.  *   - A diffuse color
  12.  * 
  13.  * PARAMETERS:
  14.  *   Ks:    controls retroreflective lobe
  15.  *   Kd:    scales diffuse color
  16.  *   Ka:    ambient component (affects diffuse color only)
  17.  *   sheen:    color of retroreflective lobe and horizon scattering
  18.  *   roughness: shininess of fabric (controls retroreflection only)
  19.  *
  20.  * ANTIALIASING: should antialias itself fairly well
  21.  *
  22.  * AUTHOR: written by Stephen H. Westin, Ford Motor Company
  23.  *
  24.  * HISTORY:
  25.  *     2001.02.01    westin@graphics.cornell.edu
  26.  *            Fixed retroreflection lobe (sign error); added
  27.  *            "backscatter" parameter to control it; added
  28.  *            "edginess" parameter to control horizon scatter;
  29.  *            defined SQR()
  30.  *
  31.  * prev modified  28 January 1997 S. H. Westin
  32.  */
  33.  
  34. #define SQR(A) ((A)*(A))
  35.  
  36. surface
  37. SHW_velvet (float Ka = 0.05,
  38.               Kd = 0.1,
  39.               Ks = 0.1;
  40.         float backscatter = 0.1,
  41.         edginess = 10;
  42.         color sheen = .25;
  43.         float roughness = .1;
  44.   )
  45. {
  46.   normal Nf;                     /* Normalized normal vector */
  47.   vector V;                      /* Normalized eye vector */
  48.   vector H;                      /* Bisector vector for Phong/Blinn */
  49.   vector Ln;                     /* Normalized vector to light */
  50.   color shiny;                   /* Non-diffuse components */
  51.   float cosine, sine;            /* Components for horizon scatter */
  52.  
  53.   Nf = faceforward (normalize(N), I);
  54.   V = -normalize (I);
  55.  
  56.   shiny = 0;
  57.   illuminance ( P, Nf, 1.57079632679489661923 /* Hemisphere */ ) {
  58.     Ln = normalize ( L );
  59.     /* Retroreflective lobe */
  60.     cosine = max ( Ln.V, 0 );
  61.     shiny += pow ( cosine, 1.0/roughness ) * backscatter
  62.       * Cl * sheen;
  63.     /* Horizon scattering */
  64.     cosine = max ( Nf.V, 0 );
  65.     sine = sqrt (1.0-SQR(cosine));
  66.     shiny += pow ( sine, edginess ) * Ln.Nf * Cl * sheen;
  67.   }
  68.  
  69.   Oi = Os;
  70.   /* Add in diffuse color */
  71.   Ci = Os * (Ka*ambient() + Kd*diffuse(Nf)) * Cs + shiny;
  72.  
  73. }
  74.  
  75.